package cn.xp.web;

import cn.xp.domain.Building;
import cn.xp.dto.BuilDDto;
import cn.xp.dto.BuilDTypeDto;
import cn.xp.service.IBuildingService;
import cn.xp.util.JSONResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/api/build")
public class BuildingController {

    @Autowired
    private IBuildingService buildingService;

    @GetMapping("/{id}")
    public Building findOne(@PathVariable("id") Long id){
       return buildingService.findOne(id);
    }

    @PostMapping("/addFloor")
    public JSONResult<Building> addFloor(@RequestBody Building[] buildings){
        return buildingService.addFloor(buildings);
    }

//    localhost:8080/api/build/getDeviceListByBuildId?id=
    @GetMapping("/getDeviceListByBuildId/{id}")
    public JSONResult<BuilDDto> getDeviceListByBuildId(@PathVariable("id") Long id){
        return buildingService.getDeviceListByBuildId(id);
    }
    @GetMapping("/getDeviceListByDeviceType/{id}")
    public JSONResult<BuilDTypeDto> getDeviceListByDeviceType(@PathVariable("id") Long id){
        return buildingService.getDeviceListByDeviceType(id);
    }
}
